package com.guldan.jaina.provider;

import com.guldan.core.dubbo.client.ResponseDTO;
import com.guldan.core.search.Pagination;
import com.guldan.jaina.dto.news.NewsDTO;
import com.guldan.jaina.dto.news.NewsSearchDTO;
import com.guldan.jaina.manager.NewsManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by Silas.
 * Date: 2017/1/24
 * Time: 12:00
 */
@Component
public class NewsProviderImpl implements INewsProvider {

    @Autowired
    private NewsManager newsManager;

    @Override
    public ResponseDTO<NewsDTO> get(Integer newsId) {
        ResponseDTO<NewsDTO> responseDTO = new ResponseDTO<>();
        responseDTO.setData(newsManager.get(newsId));
        return responseDTO;
    }

    @Override
    public ResponseDTO<NewsDTO> save(NewsDTO dto) {
        ResponseDTO<NewsDTO> responseDTO = new ResponseDTO<>();
        responseDTO.setData(newsManager.save(dto));
        return responseDTO;
    }

    @Override
    public ResponseDTO<Boolean> delete(Integer newsId) {
        ResponseDTO<Boolean> responseDTO = new ResponseDTO<>();
        responseDTO.setData(newsManager.delete(newsId));
        return responseDTO;
    }

    @Override
    public ResponseDTO<Pagination<NewsDTO>> list(NewsSearchDTO searchDTO) {
        ResponseDTO<Pagination<NewsDTO>> responseDTO = new ResponseDTO<>();
        responseDTO.setData(newsManager.list(searchDTO));
        return responseDTO;
    }


}
